<%@ page language="java" pageEncoding="utf-8" isELIgnored="false" import="java.util.*,com.demo.entity.User"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%
String baseUrl = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
%>
<!DOCTYPE html>
<html>
<base href="<%=baseUrl%>"/>
<head>
<meta charset="UTF-8">
<title></title>
<style>
</style>
<body>
<h1>JSTL标签库和EL语言表达式</h1>
关于作用域scope：
request设置的属性只能在：当前页面和请求转发的后续页面获取到
session设置的属性只能在：所有页面，前提是session还没超时
application设置的属性只能在：所有页面

<c:set var="id" value="10" scope="request"/>
<c:set var="id" value="2" scope="session"/>
<c:set var="id" value="3" scope="application"/>
<c:out value="${requestScope.id}"/>
<c:out value="${sessionScope.id}"/>
<c:out value="${applicationScope.id}"/>

${id}


<%
List<User> list = new ArrayList<User >();
for(int i=0;i<5;i++){
	User user = new User();
	user.setUsername("用户"+i);
	list.add(user);
}
request.setAttribute("users", list);
%>
<h2>迭代标签</h2>

<c:forEach items="${requestScope.users}" var="u">
	${u.username}
</c:forEach>


<h2>c:if标签</h2>
<c:set var="movie" value="珍珠港123" scope="request"/>
<c:if test="${movie == '珍珠港'}">电影名叫珍珠港</c:if>
<c:if test="${movie != '珍珠港'}">电影名不是叫珍珠港</c:if>

<h2>c:when标签</h2>
<c:choose>
<c:when test="${id == 1}">id=1</c:when>
<c:when test="${id == 2}">id=2</c:when>
<c:when test="${id == 3}">id=3</c:when>
<c:otherwise>都不是</c:otherwise>
</c:choose>

<h2>fmt标签：格式化日期/时间、货币</h2>
<c:set var="date" value="<%=new java.util.Date() %>" scope="request"/>
<%-- <fmt:formatDate value="${date}" pattern="MM-dd-yyyy HH:mm"/> --%>
<fmt:formatDate value="${date}" type="both"/>


<h2>辅助标签</h2>
<c:remove var="movie"/>
<c:if test="${!empty movie}">
	<c:redirect url="login.jsp"/>
</c:if>
</body>
</html>
